package com.fs.sys.web;

import com.fs.common.bean.LoginResp;
import com.fs.sys.service.LoginService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.security.PermitAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录控制器
 *
 * @author LiuQi 2024/8/15-10:18
 * @version V1.0
 **/
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Autowired
    private LoginService loginService;

//    @Autowired
//    private WxLoginService wxLoginService;

    @GetMapping("login")
    @PermitAll
    public LoginResp login(String username, String password) {
        return loginService.login(username, password);
    }

    @Operation(description = "退出登录")
    @GetMapping("logout")
    @PermitAll
    public void logout() {
        loginService.logout();
    }

    /**
     * 手机号登录
     *
     * @param phone 手机号
     * @param code  验证码
     * @return 登录结果
     */
    @GetMapping("phone-login")
    public LoginResp loginByPhone(String phone, String code) {
        return loginService.loginByPhone(phone, code);
    }

    /**
     * 应用登录
     *
     * @param appId     应用id
     * @param appSecret 应用密钥
     * @return 登录结果
     */
    @GetMapping("app-login")
    @PermitAll
    public String clientLogin(String appId, String appSecret) {
        return loginService.loginByApp(appId, appSecret);
    }

//    /**
//     * 微信授权登录
//     */
//    @GetMapping("wx")
//    @PermitAll
//    public LoginResp wxLogin(String code,
//                             @RequestParam(required = false)String nickname,
//                             @RequestParam(required = false) String photo) {
//        return wxLoginService.login(code, nickname, photo);
//    }
}
